
<?php
/**
 * Yii view form
 *
 * @author <KTD SOFT>
 * @since Jan 11, 2013 - 2:46:02 PM
 */
?>
<?php if (Yii::app()->user->hasFlash('contact')): ?>
    <div class="alert alert-error">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>Error!</strong> <?php echo Yii::app()->user->getFlash('contact'); ?>.
    </div>
<?php endif; ?>
<ul class="tab-menu nav nav-tabs tabs-main" id="myTab">
    <li class="active">
        <a data="#index_tab" class="tab-control">
            <?php echo Yii::t('post', 'Category'); ?>

        </a>
    </li>
    <li>
        <a data="#seo_tab" class="tab-control">
            <?php echo Yii::t('post', 'SEO') ?>
        </a>
    </li>
    <div class="clear"></div>
</ul>
<div id="index_tab" class="project_tab">
    <?php
    $this->beginWidget('MyActiveForm', array(
        'model'   => $this->model,
        'title'   => $this->pageTitle,
        'columns' => array(
            'name',
            'rank',
            array(
                'field'       => 'parent_id',
                'type'        => 'dropDownList',
                'data'        => Category::getPublicArrayForCat(array($this->model->id)),
                'htmlOptions' => array('class' => ""),
            ),
            array(
                'field'       => 'status',
                'type'        => 'dropDownList',
                'data'        => Category::getArrayStatus(),
                'htmlOptions' => array('class' => ""),
            ),
        ),
    ));
    ?>
</div>
<div id="seo_tab" class="project_tab hide tabs-main-content padding-null">
    <div class="grid-title">
        <div class="pull-left"><?php echo $this->pageTitle ?></div>

        <div class="clear"></div>
    </div>
    <div class="grid-content">
        <div class="formRow">
            <b> <?php echo Yii::t('sub_all', 'Preview') ?> </b>
            <div class="formRight">
                <div class="span10">
                    <a id="title_seo"  href="<?php
                    echo Yii::app()->createAbsoluteUrl('post/view', array(
                        'url'  => $this->model->url,
                        'lang' => Yii::app()->language
                    ))
                    ?>">
                           <?php echo $this->model->titleSeo ?>
                    </a>
                    <div class="url_seo"  >
                        <div id="original_url">
                            <?php
                            echo Yii::app()->createAbsoluteUrl('post/view', array(
                                'url'  => $this->model->url,
                                'lang' => Yii::app()->language
                            ));
                            ?>
                        </div>
                        <div id="change_url" class="hide">
                            <?php
                            echo Yii::app()->getBaseUrl(true) . '/' . Yii::app()->language . '/' . '<span id="url_seo"></span>.html';
                            ?>
                        </div>
                    </div>

                    <div id="meta_desc">
                        <?php
                        if ($this->model == null)
                        {
                            echo $this->model->description;
                        }
                        else
                        {
                            echo $this->model->meta_desc;
                        }
                        ?>
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
        </div>
        <div class="formRow">
            <label>
                <?php echo Yii::t('post', "Url") ?>
            </label>
            <div class="formRight">
                <input type="text" id="Category_url" class="span10" name="Category[url]" value="<?php echo $this->model->url; ?>">
            </div>
            <div class="clear"></div>
        </div>
        <div class="formRow">
            <label>
                <?php echo Yii::t('post', "Meta Description") ?>
            </label>
            <div class="formRight">
                <textarea id="desc" class="resize-text span10" name="Category[meta_desc]"><?php echo $this->model->meta_desc; ?></textarea>
            </div>
            <div class="clear"></div>
        </div>
        <div class="formRow">
            <label>
                <?php echo Yii::t('sub_all', "Meta keyword") ?>
            </label>
            <div class="formRight">
                <textarea id="desc" class="resize-text span10" name="Category[meta_key]"><?php echo $this->model->meta_key; ?></textarea>
            </div>
            <div class="clear"></div>
        </div>
        <div class="formRow">
            <label>
                <?php echo Yii::t('sub_all', "Seo title") ?>
            </label>
            <div class="formRight">
                <textarea id="seo_title"class="resize-text span10" name="Category[seo_title]"><?php echo $this->model->seo_title; ?></textarea>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
<?php $this->endWidget(); ?>
<script>
    $(function () {
        $('#Category_name').keyup(function () {
            title = $('#Category_name').val();
            $('#Category_url').val(convertToSlug(title));
        });
        $('#Category_name').keyup(function () {
            title = $('#Category_name').val();
            $('#seo_title').text(title);
        });
        $('#seo_title').keyup(function () {
            title = $('#seo_title').val();
            $('#title_seo').text(title);
        });
        $('#Category_name').keyup(function () {
            title = $('#Category_name').val();
            $('#title_seo').text(title);
        });
        $('#Category_name').keyup(function () {
            title = $('#Category_name').val();
            $('#url_seo').text(convertToSlug(title));
        });
        $('#Category_url').keyup(function () {
            title = $('#Category_url').val();
            $('#url_seo').text(convertToSlug(title));
        });
        $('#Category_url').keyup(function () {
            $('#original_url').hide();
            $('#change_url').show();
        });
        $('#Category_name').keyup(function () {
            $('#change_url').removeClass('hide');
            $('#original_url').hide()();
            $('#change_url').show();
        });
        $('#desc').keyup(function () {
            title = $('#desc').val();
            $('#meta_desc').text(title);
        });
    });
    $('.tab-control').parent().click(function () {
        $('.project_tab').each(function () {
            $(this).addClass('hide');
        });

        id = $(this).children('a').attr('data');
        $(id).removeClass('hide');

        $('.tab-control').each(function () {
            $(this).parent().removeClass('active');
        });

        $(this).addClass('active');
    });
</script>
